package org.codeart.apipassenger.service;

import org.codeart.apipassenger.remote.ServiceOrderClient;
import org.codeart.common.constant.IdentityEnum;
import org.codeart.common.dto.OrderInfo;
import org.codeart.common.request.OrderRequest;
import org.codeart.common.util.HttpStatus;
import org.codeart.common.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderService {

    @Autowired
    private ServiceOrderClient serviceOrderClient;

    public boolean add(OrderRequest orderRequest, String deviceCode) {
        R<Void> r = serviceOrderClient.add(orderRequest, deviceCode);
        return r.getCode() == HttpStatus.HTTP_OK;
    }

    /**
     * 取消订单
     * @param orderId 订单id
     */
    public boolean cancel(Long orderId) {
        R<Void> r = serviceOrderClient.cancel(orderId, IdentityEnum.PASSENGER.value());
        return r.getCode() == HttpStatus.HTTP_OK;
    }

    public R<OrderInfo> detail(Long orderId) {
        return serviceOrderClient.detail(orderId);
    }

    public R<OrderInfo> currentOrder(String phone, String identity) {
        return serviceOrderClient.current(phone, identity);
    }
}
